<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="http://svn.pear.php.net/templates/pear/styles.css" rel="stylesheet" media="screen" />
<style type="text/css">
.testsuite {margin:1em 0.5em;border-top:1px dashed;}
.testcase {clear:both;}
.method,.error,.failure {float:left;}
.failure {background-color:#FFC7C7;margin-left:0.3em;}
.error {background-color:#FFFFC7;margin-left:0.3em;}
</style>
<title></title>
</head>
<body>
<div id="header">
            <div id="headerimg">
                <h1><a href="http://pear.cweiske.de/"><abbr title="PHP Extension and Application Repository">PEAR</abbr> Unit Test Results</a></h1>
            </div>
        </div>
        <div id="content">
<?php
if (!isset($argv[1])) {
  die("Pass result.xml path\n");
}
$file = $argv[1];

class PEAR_UnitTest_Results
{
    public $testsuites = array();
    public $file;
    
    public function __construct($filename)
    {
		$xml = simplexml_load_file($filename);
		foreach ($xml as $testsuite) {
		    $this->testsuites[] = new PEAR_UnitTest_Results_TestSuite($testsuite);
		}
    }
	
	public function toHtml()
	{
	    $t = '<h1>PEAR Unit Test Result Summary</h1>';
	    foreach ($this->testsuites as $suite) {
	        $t .= $suite->toHtml();
	    }
	    return $t;
	}
}

class PEAR_UnitTest_Results_TestSuite
{
    public $name;
    public $tests;
    public $failures;
    public $errors;
    public $output;
    public function __construct($testsuite)
    {
        $attributes = $testsuite->attributes();
        foreach (array('name','tests','failures','errors') as $att) {
            $this->$att = $attributes[$att];
        }
	    if ($attributes['failures'] || $attributes['errors']) {
		    foreach ($testsuite as $test) {
		        switch($test->getName()) {
		            case 'testsuite':
		                $this->output[] = new PEAR_UnitTest_Results_TestSuite($test);
		                break;
		            case 'testcase':
		                $this->output[] = new PEAR_UnitTest_Results_TestCase($test);
		                break;
		            default:
		                echo 'I don\'t know how to handle '.$testsuite->getName().' elements.';
		        }
		    }
	    }
    }
    
    public function toHtml()
    {
        $t = '';
        if (($this->errors > 0) || ($this->failures > 0)) {
	        $t = '<div class="testsuite"><h2 class="name">'.$this->name.'</h2>';
	        $t .= $this->tests.' tests, with '.$this->errors.' warnings and '.$this->failures.' failures.';
	        foreach ($this->output as $out) {
	            $t .= $out->toHtml();
	        }
	        $t .= '</div>';
        }
        return $t;
    }
}

class PEAR_UnitTest_Results_Message
{
    public $message;
    public $type;
    function toHtml()
    {
        $att = $this->message->attributes();
        $n = "\n";
        $t = '<div class="'.$this->type.'">';
	    $t .= $att['message'].$n.
	    str_replace('/data/cvs/pear/','',$this->message). '</div>'.$n;
        return $t;
    }
}
class PEAR_UnitTest_Results_TestCase
{
    public $testcase;
    public $message;
    public function __construct($testcase)
    {
        $this->testcase = $testcase;
        foreach ($testcase as $xmlmessage) {
            switch($xmlmessage->getName()) {
                case 'failure':
                    $this->message = new PEAR_UnitTest_Results_Failure($xmlmessage);
                    break;
                case 'error':
                    $this->message = new PEAR_UnitTest_Results_Error($xmlmessage);
                    break;
                default:
                    echo 'I don\'t know how to handle '.$xmlmessage->getName().' elements';
                    break;
            }
        }
    }
    
    public function toHtml()
    {
        $t = '';
        if (isset($this->message)) {
	        $n = "\n";
	        $att = $this->testcase->attributes();
	        $t = '<div class="testcase">'.$n.
	        '<div class="method">'.$att['class'].'-&gt;'.$att['name'].'()</div>';
	        $t .= $this->message->toHtml();
	        $t .= '</div><div style="clear:both"></div>'.$n;
        }
        return $t;
    }
}
class PEAR_UnitTest_Results_Failure extends PEAR_UnitTest_Results_Message
{
    function __construct($failure)
    {
        $this->type = 'failure';
        $this->message = $failure;
    }
}

class PEAR_UnitTest_Results_Error extends PEAR_UnitTest_Results_Message
{
    public $error;
    function __construct($error)
    {
        $this->type = 'error';
        $this->message = $error;
    }
}

$r = new PEAR_UnitTest_Results($file);

echo $r->toHtml();
#highlight_file(__FILE__);


?>
</div>
</body>
</html>